package com.itheima.autoCode.service.strategy;

import cn.hutool.core.collection.CollUtil;
import com.itheima.w_util.SpringBeanHelperUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class CodeStyleStrategyRegistratar  {

    public CodeStyleStrategy findService(CodeStyleEnums codeStyleEnums) {
        List<CodeStyleStrategy> beans = SpringBeanHelperUtil.getBeans(CodeStyleStrategy.class);
        if (CollUtil.isEmpty(beans)){
            return null;
        }
        for (int i = 0; i < beans.size(); i++) {
            CodeStyleEnums getIdentity = beans.get(i).getIdentity();
            if (getIdentity.equals(codeStyleEnums)){
                return beans.get(i);
            }
        }
        return null;
    }
}
